package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Member;
import com.itheima.service.PersonalCenterService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/personalCenter")
public class PersonalCenterController {

    @Reference
    private PersonalCenterService personalCenterService;

    @RequestMapping("/getPersonData")
    public Result getPersonData(String telephone) {

        try {
            Member member = personalCenterService.findByTelephone(telephone);
            return new Result(true, "查询会员成功", member);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "查询会员失败");
        }

    }

    /**
     * 修改个人中心
     *
     * @param member
     * @return
     */
    @RequestMapping("/modifyPersonalCenter")
    public Result modifyPersonalCenter(@RequestBody Member member) {
        try {
            personalCenterService.modifyPersonalCenter(member);
            return new Result(true, MessageConstant.EDIT_MEMBER_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.EDIT_MEMBER_FAIL);
        }
    }

}
